#version 410
#extension GL_EXT_gpu_shader4 : enable

//uniform mat4 Modelview;
//uniform mat3 NormalMatrix;
layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;
in float tePrimitive[3];
in vec3 tePosition[3];
in vec3 teNormal[3];
in vec3 tePatchDistance[3];
out vec3 gNormal;
out vec3 gPatchDistance;
out vec3 gTriDistance;
//out float gPrimitive;

void main()
{
    //vec3 A = tePosition[2] - tePosition[0];
    //vec3 B = tePosition[1] - tePosition[0];
    //gFacetNormal = NormalMatrix * normalize(cross(A, B));
    //gFacetNormal = normalize((teNormal[0]+teNormal[1]+teNormal[2])/3);
    //gFacetNormal = normalize(vec3(0, 0, 1));

	//gPrimitive = tePrimitive[0];
	//gl_PrimitiveID = primitive;
	gNormal = teNormal[0];
    gPatchDistance = tePatchDistance[0];
    gTriDistance = vec3(1, 0, 0);
    gl_Position = gl_in[0].gl_Position;
    EmitVertex();

	//gPrimitive = tePrimitive[1];
	gNormal = teNormal[1];
    gPatchDistance = tePatchDistance[1];
    gTriDistance = vec3(0, 1, 0);
    gl_Position = gl_in[1].gl_Position; 
    EmitVertex();

	//gPrimitive = tePrimitive[2];
	gNormal = teNormal[2];
    gPatchDistance = tePatchDistance[2];
    gTriDistance = vec3(0, 0, 1);
    gl_Position = gl_in[2].gl_Position; 
    EmitVertex();

    EndPrimitive();
}
